package com.itheima.huikebackend.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.huikebackend.common.PageResult;
import com.itheima.huikebackend.dto.RoleDTO;
import com.itheima.huikebackend.entity.SysRole;
import com.itheima.huikebackend.mapper.RoleMapper;
import com.itheima.huikebackend.service.RoleService;
import com.itheima.huikebackend.vo.RoleVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @ClassName: RoleServiceImpl
 * @description:
 * @author: zhao qianfeng
 * @date: 2023年08月07日
 * @version: 1.0
 */
@Service
@RequiredArgsConstructor
public class RoleServiceImpl implements RoleService {

    private final RoleMapper roleMapper;
    @Override
    public HashMap<String, Object> page(RoleDTO roleDTO) {
        PageHelper.startPage(roleDTO.getPageNum(),roleDTO.getPageSize());
        SysRole sysRole = new SysRole();
        BeanUtils.copyProperties(roleDTO,sysRole);
        Page<RoleVO> roleVOS = roleMapper.selectpage(sysRole);
        //用hashmap封装
        HashMap map = new HashMap();
        map.put("total", roleVOS.getTotal());
        map.put("rows", roleVOS.getResult());

        return map;
    }
}
